<?php
/**
 * Created by PhpStorm.
 * User: cc
 * Date: 2024/10/16
 * Time: 上午10:38
 */

namespace app\astrologer\controller\v8;

use app\astrologer\controller\AstrAuth;
use app\zyhsapi\model\ZyhsConsultChatRecordAstr;
use think\response\Json;

class Consult extends AstrAuth
{

    /**
     * 获取咨询备注
     * @return Json
     * @throws \Exception
     */
    public function consultRemark()
    {
        $uid = input('uid/d', 0);
        $appType = input('app_type/d', 0);
        $zyhsConsultChatRecordAstrModel = new ZyhsConsultChatRecordAstr();
        $id = $zyhsConsultChatRecordAstrModel->getIdByAstrIdAndUid($this->astrInfo['id'], $appType, $uid);
        if ($id)
        {
            $info = $zyhsConsultChatRecordAstrModel->getInfoById($id);
            return show(config('code.success'), 'ok', ['remark' => $info['extend']['consult_remark'] ?? '']);
        }
        return show(config('code.success'), 'ok', ['remark' => '']);
    }

    /**
     * 编辑咨询备注
     * @return Json
     * @throws \Exception
     */
    public function alterConsultRemark()
    {
        $uid = input('uid/d', 0);
        $appType = input('app_type/d', 0);
        $remark = input('remark/s', '');
        $zyhsConsultChatRecordAstrModel = new ZyhsConsultChatRecordAstr();
        $id = $zyhsConsultChatRecordAstrModel->getIdByAstrIdAndUid($this->astrInfo['id'], $appType, $uid);
        if ($id)
        {
            $info = $zyhsConsultChatRecordAstrModel->getInfoById($id);
            $info['extend']['consult_remark'] = $remark;
            $res = $zyhsConsultChatRecordAstrModel->UpdateData($id, $this->astrInfo['id'], [
                'extend' => json_encode($info['extend'], true),
            ]);
            if ($res)
            {
                return show(config('code.success'), 'ok');
            }
        }
        return show(config('code.success'), 'ok');
    }

    /**
     * 编辑咨询用户备注
     * @return Json
     * @throws \Exception
     */
    public function alterUserConsultRemark()
    {
        $uid = input('uid/d', 0);
        $appType = input('app_type/d', 0);
        $remark = input('remark/s', '');
        $zyhsConsultChatRecordAstrModel = new ZyhsConsultChatRecordAstr();
        $id = $zyhsConsultChatRecordAstrModel->getIdByAstrIdAndUid($this->astrInfo['id'], $appType, $uid);
        if ($id)
        {
            $info = $zyhsConsultChatRecordAstrModel->getInfoById($id);
            $info['extend']['user_remark'] = $remark;
            $res = $zyhsConsultChatRecordAstrModel->UpdateData($id, $this->astrInfo['id'], [
                'extend' => json_encode($info['extend'], true),
            ]);
            if ($res)
            {
                return show(config('code.success'), 'ok');
            }
        }
        return show(config('code.error'), 'err');
    }
}
